package com.ruoyi.quartz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quartz.domain.TbListData;
import com.ruoyi.quartz.service.ITbListDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 淘宝房源Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@RestController
@RequestMapping("/quartz/tbData")
public class TbListDataController extends BaseController
{
    @Autowired
    private ITbListDataService tbListDataService;

    /**
     * 查询淘宝房源列表
     */
    @PreAuthorize("@ss.hasPermi('quartz:tbData:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbListData tbListData)
    {
        startPage();
        List<TbListData> list = tbListDataService.selectTbListDataList(tbListData);
        return getDataTable(list);
    }

    /**
     * 查询淘宝房源列表
     */
    @PreAuthorize("@ss.hasPermi('quartz:tbData:list')")
    @GetMapping("/listDetail")
    public TableDataInfo listDetail(TbListData tbListData)
    {
        Boolean isHistory = Boolean.valueOf(ServletUtils.getParameter("isHistory"));
        startPage();
        List<TbListData> list = tbListDataService.selectTbListDataListByBusinessId(tbListData, isHistory);
        return getDataTable(list);
    }

    /**
     * 导出淘宝房源列表
     */
    @PreAuthorize("@ss.hasPermi('quartz:tbData:export')")
    @Log(title = "淘宝房源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbListData tbListData)
    {
        List<TbListData> list = tbListDataService.selectTbListDataList(tbListData);
        ExcelUtil<TbListData> util = new ExcelUtil<TbListData>(TbListData.class);
        util.exportExcel(response, list, "淘宝房源数据");
    }

    /**
     * 获取淘宝房源详细信息
     */
    @PreAuthorize("@ss.hasPermi('quartz:tbData:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbListDataService.selectTbListDataById(id));
    }

    /**
     * 新增淘宝房源
     */
    @PreAuthorize("@ss.hasPermi('quartz:tbData:add')")
    @Log(title = "淘宝房源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbListData tbListData)
    {
        return toAjax(tbListDataService.insertTbListData(tbListData));
    }

    /**
     * 修改淘宝房源
     */
    @PreAuthorize("@ss.hasPermi('quartz:tbData:edit')")
    @Log(title = "淘宝房源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbListData tbListData)
    {
        return toAjax(tbListDataService.updateTbListData(tbListData));
    }

    /**
     * 删除淘宝房源
     */
    @PreAuthorize("@ss.hasPermi('quartz:tbData:remove')")
    @Log(title = "淘宝房源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbListDataService.deleteTbListDataByIds(ids));
    }
}
